﻿package net.area80.sitemanager.display
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.events.Event;
	
	import gs.TweenLite;
	
	/**
	* FreezeClip
	* @author Wissarut Pimanmassuriya
	*/
	public class FreezeClip extends Sprite
	{
		protected var freezeColor:int;
		protected var freezeAlpha:Number;
		private var w:uint = 0;
		private var h:uint = 0;
		
		public function FreezeClip (color:int = 0x000000, alpha:Number = 0, w:uint=0, h:uint=0):void {
				this.w = w;
				this.h = h;
				freezeColor = color;
				freezeAlpha = alpha;
				
				addEventListener(Event.ADDED_TO_STAGE, create, false, 0, true);	
				addEventListener(Event.REMOVED_FROM_STAGE, dispose, false, 0, true);	
		}
		public function fadeUp ():void {
			alpha = 0;
			new TweenLite(this, 0.5, { alpha:1 } );
		}
		private function resize (e:Event):void {
			this.width = stage.stageWidth;
			this.height = stage.stageHeight;
		}
		public function fadeDown ():void {
			new TweenLite(this, 0.5, { alpha:0 } );
		}
		protected function create (e:Event):void {
			stage.addEventListener(Event.RESIZE, resize);
			graphics.beginFill(freezeColor, freezeAlpha);
			graphics.drawRect(0, 0,((w==0)? stage.stageWidth:w), ((h==0)? stage.stageHeight:h));
		}
		protected function dispose (e:Event):void {
			stage.removeEventListener(Event.RESIZE, resize);
			removeEventListener(Event.ADDED_TO_STAGE, create);	
			removeEventListener(Event.REMOVED_FROM_STAGE, dispose);
			graphics.clear();
		}
	}
	
}